home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 24
/
Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso
/
Aminet
/
dev
/
c
/
vbcc.lha
/
vbcc
/
parse_expr.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-12-30
|
19KB
|
771 lines
/* $VER: vbcc (parse_expr.c) V0.5 */
#include "vbc.h"
static char FILE_[]=__FILE__;
np expression(void)
/* Komma-Ausdruecke */
{
np left,right,new;
left=assignment_expression();
if(!left->flags) return 0;
killsp();
while(*s==','){
s++;
killsp();
right=assignment_expression();
new=mymalloc(NODES);
new->left=left;
new->right=right;
new->ntyp=0;
new->flags=KOMMA;
left=new;
killsp();
}
return left;
}
np assignment_expression(void)
/* Zuweisungsausdruecke */
{
np left,new;int c=0;
left=conditional_expression();
killsp();
if(*s!='='&&s[1]!='='&&s[2]!='=') return left;
if(*s=='=') {c=ASSIGN;s++;}
else if(*s=='*'&&s[1]=='=') {c=ASSIGNMULT;s+=2;}
else if(*s=='/'&&s[1]=='=') {c=ASSIGNDIV;s+=2;}
else if(*s=='%'&&s[1]=='=') {c=ASSIGNMOD;s+=2;}
else if(*s=='+'&&s[1]=='=') {c=ASSIGNADD;s+=2;}
else if(*s=='-'&&s[1]=='=') {c=ASSIGNSUB;s+=2;}
else if(*s=='&'&&s[1]=='=') {c=ASSIGNAND;s+=2;}
else if(*s=='^'&&s[1]=='=') {c=ASSIGNXOR;s+=2;}
else if(*s=='|'&&s[1]=='=') {c=ASSIGNOR;s+=2;}
else if(*s=='<'&&s[1]=='<') {c=ASSIGNLSHIFT;s+=3;}
else if(*s=='>'&&s[1]=='>') {c=ASSIGNRSHIFT;s+=3;}
else return left;
new=mymalloc(NODES);
new->left=left;
new->ntyp=0;
if(c==ASSIGN){
new->right=assignment_expression();
new->flags=ASSIGN;
}else{
/* ASSIGNOP(a,b)->ASSIGN(a,OP(a,b)) */
new->flags=ASSIGNADD; /* nur um zum Merken, dass nur einmal */
/* ausgewertet werden darf */
new->right=mymalloc(NODES);
new->right->left=left;
new->right->right=assignment_expression();
new->right->ntyp=0;
if(c==ASSIGNMULT) new->right->flags=MULT;
else if(c==ASSIGNDIV) new->right->flags=DIV;
else if(c==ASSIGNMOD) new->right->flags=MOD;
else if(c==ASSIGNADD) new->right->flags=ADD;
else if(c==ASSIGNSUB) new->right->flags=SUB;
else if(c==ASSIGNAND) new->right->flags=AND;
else if(c==ASSIGNXOR) new->right->flags=XOR;
else if(c==ASSIGNOR) new->right->flags=OR;
else if(c==ASSIGNLSHIFT) new->right->flags=LSHIFT;
else if(c==ASSIGNRSHIFT) new->right->flags=RSHIFT;
}
return new;
}
np conditional_expression(void)
/* Erledigt ? : */
{
np left,new;
left=logical_or_expression();
killsp();
if(*s=='?'){
s++;killsp();
new=mymalloc(NODES);
new->flags=COND;
new->ntyp=0;
new->left=left;
new->right=mymalloc(NODES);
new->right->flags=COLON;
new->right->ntyp=0;
new->right->left=expression();
killsp();
if(*s==':'){s++;killsp();} else error(70);
new->right->right=conditional_expression();
left=new;
killsp();
}
return left;
}
np logical_or_expression(void)
/* Erledigt || */
{
np left,right,new;
left=logical_and_expression();
killsp();
while(*s=='|'&&s[1]=='|'){
s+=2;
killsp();
right=logical_and_expression();
new=mymalloc(NODES);
new->left=left;
new->right=right;
new->flags=LOR;
new->ntyp=0;
left=new;
killsp();
if(*s=='&'&&s[1]=='&') error(222);
}
return left;
}
np logical_and_expression(void)
/* Erledigt && */
{
np left,right,new;
left=inclusive_or_expression();
killsp();
while(*s=='&'&&s[1]=='&'){
s+=2;
killsp();
right=inclusive_or_expression();
new=mymalloc(NODES);
new->left=left;
new->right=right;
new->flags=LAND;
new->ntyp=0;
left=new;
killsp();
if(*s=='|'&&s[1]=='|') error(222);
}
return left;
}
np inclusive_or_expression(void)
/* Erledigt | */
{
np left,right,new;
left=exclusive_or_expression();
killsp();
while(*s=='|'&&s[1]!='|'&&s[1]!='='){
s++;
killsp();
right=exclusive_or_expression();
new=mymalloc(NODES);
new->left=left;
new->right=right;
new->flags=OR;
new->ntyp=0;
left=new;
killsp();
}
return left;
}
np exclusive_or_expression(void)
/* Erledigt ^ */
{
np left,right,new;
left=and_expression();
killsp();
while(*s=='^'&&s[1]!='='){
s++;
killsp();
right=and_expression();
new=mymalloc(NODES);
new->left=left;
new->right=right;
new->flags=XOR;
new->ntyp=0;
left=new;
killsp();
}
return left;
}
np and_expression(void)
/* Erledigt & */
{
np left,right,new;
left=equality_expression();
killsp();
while(*s=='&'&&s[1]!='&'&&s[1]!='='){
s++;
killsp();
right=equality_expression();
new=mymalloc(NODES);
new->left=left;
new->right=right;
new->flags=AND;
new->ntyp=0;
left=new;
killsp();
}
return left;
}
np equality_expression(void)
/* Erledigt == und != */
{
np left,right,new;int c;
left=relational_expression();
killsp();
while((*s=='='||*s=='!')&&s[1]=='='){
if(*s=='!') c=INEQUAL; else c=EQUAL;
s+=2;
killsp();
right=relational_expression();
new=mymalloc(NODES);
new->left=left;
new->right=right;
new->flags=c;
new->ntyp=0;
left=new;
killsp();
}
return left;
}
np relational_expression(void)
/* Erledigt <,>,<=,>= */
{
np left,right,new;int c;
left=shift_expression();
killsp();
while((*s=='<'&&s[1]!='<')||(*s=='>'&&s[1]!='>')){
if(*s++=='<'){
if(*s=='='){s++;c=LESSEQ;}else c=LESS;
}else{
if(*s=='='){s++;c=GREATEREQ;}else c=GREATER;
}
killsp();
right=shift_expression();
new=mymalloc(NODES);
new->left=left;
new->right=right;
new->flags=c;
new->ntyp=0;
left=new;
killsp();
}
return left;
}
np shift_expression(void)
/* Erledigt <<,>> */
{
np left,right,new;int c;
left=additive_expression();
killsp();
while((*s=='<'&&s[1]=='<'&&s[2]!='=')||(*s=='>'&&s[1]=='>'&&s[2]!='=')){
if(*s=='<') c=LSHIFT; else c=RSHIFT;
s+=2;
killsp();
right=additive_expression();
new=mymalloc(NODES);
new->left=left;
new->right=right;
new->flags=c;
new->ntyp=0;
left=new;
killsp();
}
return left;
}
np additive_expression(void)
/* Erledigt +,- */
{
np left,right,new;int c;
left=multiplicative_expression();
killsp();
while((*s=='+'||*s=='-')&&s[1]!='='){
if(*s++=='+') c=ADD; else c=SUB;
killsp();
right=multiplicative_expression();
new=mymalloc(NODES);
new->left=left;
new->right=right;
new->flags=c;
new->ntyp=0;
left=new;
killsp();
}
return left;
}
np multiplicative_expression(void)
/* Erledigt *,/,% */
{
np left,right,new;int c;
left=cast_expression();
killsp();
while((*s=='*'||*s=='/'||*s=='%')&&s[1]!='='){
if(*s=='*') c=MULT; else {if(*s=='/') c=DIV; else c=MOD;}
s++;
killsp();
right=cast_expression();
new=mymalloc(NODES);
new->left=left;
new->right=right;
new->flags=c;
new->ntyp=0;
left=new;
killsp();
}
return left;
}
np cast_expression(void)
/* Erledigt (typ) */
{
np new;char *imerk,buff[MAXI];
killsp();
if(*s!='('||!declaration(1)) return unary_expression();
s++;killsp();
new=mymalloc(NODES);
new->flags=CAST;
new->right=0;
imerk=ident;ident=buff;
new->ntyp=declarator(declaration_specifiers());
ident=imerk;
killsp();
if(*s!=')') error(59); else s++;
new->left=cast_expression();
return new;
}
np unary_expression(void)
/* Erledigt !,~,++,--,+,-,*,&,sizeof,__typeof */
{
np new;char *merk=s,buff[MAXI];
killsp();
if((*s!='s'&&*s!='_'&&*s!='+'&&*s!='-'&&*s!='&'&&*s!='*'&&*s!='~'&&*s!='!')||s[1]=='=') return postfix_expression();
if(*s=='s'||*s=='_'){
int fszof;
merk=s;cpbez(buff,0);s=merk;
if(strcmp("sizeof",buff)&&strcmp("__typeof",buff)){
return postfix_expression();
}else{
if(*buff=='s') fszof=1; else fszof=0;
s+=strlen(buff);
killsp();
new=mymalloc(NODES);
new->flags=CEXPR;
new->ntyp=mymalloc(TYPS);
if(fszof) new->ntyp->flags=UNSIGNED|LONG;
else new->ntyp->flags=INT;
new->ntyp->next=0;
new->right=0;
new->left=0;
if(*s=='('&&declaration(1)){
struct Typ *t;
s++;killsp();
merk=ident;ident=buff;
t=declarator(declaration_specifiers());
if(type_uncomplete(t)) error(176);
ident=merk;
if(fszof)
new->val.vulong=zl2zul(szof(t));
else
new->v